package com.mxpio.erp.common.inventory.entity;

import com.mxpio.erp.common.jpa.model.Notice;
import com.mxpio.erp.common.jpa.model.NoticeLine;
import com.mxpio.erp.common.purchase.entity.Supply;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import com.mxpio.erp.common.workshop.entity.ManufactureOrder;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * @author wupaa
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_INV_FP_NOTICE")
@Schema(description="送货计划")//使用通知单的表结果，实际业务层可以理解为单据(特殊采购订单)
public class FeedPlanNotice extends Notice {

	private static final long serialVersionUID = 1L;

	@Override
    public String initTypeCode() {
        return "FP1";
    }

    @Schema(description = "供应商编号")
    @Column(name = "PN_CODE_")
    private String pnCode;

    @Schema(description = "供应商名称")
    @Column(name = "PN_NAME_")
    private String pnName;

    @Schema(description = "对应领料出库通知单单号")
    @Column(name = "SOURCE_PICKING_NOTICE_NO_")
    private String sourcePickingNoticeNo;

    @Schema(description = "需要质检时对应验收单单号")
    @Column(name = "INQUALITY_NOTICE_NO_")
    private String inQualityNoticeNo;

    //生产订单相关字段
    @Column(name = "PRODUCT_ITEM_CODE_")
    @Schema(description = "产品编号")
    private String productItemCode;

    @Column(name = "PRODUCT_ITEM_NAME_")
    @Schema(description = "产品名称")
    private String productItemName;

    @Column(name = "PRODUCT_DRAWING_NO_")
    @Schema(description = "图号")
    private String productDrawingNo;

    @Transient
    private ManufactureOrder manufactureOrder;
    @Transient
    private List<FeedPlanNoticeLine> feedPlanNoticeLines;
    @Transient
    private Supply supply;
	@Override
	public NoticeLine createLine(OrderExcuteLineVo orderExcuteVo) {
        NoticeLine noticeLine = new FeedPlanNoticeLine();
        noticeLine.setOriginBizLineNo(orderExcuteVo.getBizOrderlineNo());
        noticeLine.setOriginBizNo(orderExcuteVo.getBizOrderNo());
        noticeLine.setItemCode(orderExcuteVo.getItemCode());
        noticeLine.setNoticeNo(this.getNoticeNo());
        noticeLine.setQuantity(orderExcuteVo.getQuantity());
        noticeLine.setSort(orderExcuteVo.getSort());
        noticeLine.setLotNo(orderExcuteVo.getLotNo());
        noticeLine.setSubLotIndex(orderExcuteVo.getSubLotIndex());
        return noticeLine;
	}

	@Override
	public List<? extends NoticeLine> getNoticeLines() {
		return feedPlanNoticeLines;
	}
}
